package juc.concurrent.forkjoin;

import java.util.concurrent.RecursiveAction;

public class MyRecursiveAction extends RecursiveAction {

    private int beginValue;
    private int endValue;
    MyRecursiveAction(int beginValue,int endValue){
        super();
        this.beginValue = beginValue;
        this.endValue = endValue;
    }

    @Override
    protected void compute() {

        System.out.println(Thread.currentThread().getName() + "------------");
        if(endValue - beginValue > 2){
            int middleValue = (endValue + beginValue)/2;
            MyRecursiveAction leftAction = new MyRecursiveAction(beginValue, middleValue);
            MyRecursiveAction rightAction = new MyRecursiveAction(middleValue +1, endValue);
            this.invokeAll(leftAction,rightAction);
        }else{
            System.out.println("打印组合为:" + beginValue + "-" + endValue);
        }
    }
}
